<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>计算器_脚本之家</title>
<script language="javascript"> 
<!--
 
	var nLast = 0;
	var bNewNum = false;
	var sLastOpr = "";
	var sLastPrompt = "";
	var result ;
 
	var sLastPro = "";
	var prompt ;
 
	function fInit(){
		result = document.getElementById("jsqResult");
		prompt = document.getElementById("jsqPrompt");
	}
 
	function inputNum (num) {
		if (bNewNum) {
			result.value  = num;
			bNewNum = false;
			if(sLastOpr == "="){
				prompt.innerHTML = num;
			}else{
				prompt.innerHTML += num;	
			}
		}else {
			if (result.value == "0"){
				result.value = num;
				prompt.innerHTML = num;
			}else{
				result.value += num;	
				prompt.innerHTML += num;	
				
			}
		}
		sLastPrompt = prompt.innerHTML;
	}
 
 
	function operate(opr)
	{
		if(!sLastPrompt){
			return;
		}
		var Readout = result.value;
		if (bNewNum && sLastOpr != "="){
			switch(opr)
			{
				case '+' :
				case '－' :			
					prompt.innerHTML = sLastPrompt+opr;	//字符串相加	
					break;
				case '×' :
				case '÷' :		
					prompt.innerHTML = "("+sLastPrompt+")"+opr;
					break;
				default :
					break;
			}
			sLastOpr = opr;
		}else{
			bNewNum = true;
			switch(sLastOpr)
			{
				case '+' :
					nLast += parseFloat(Readout);
					break;
				case '－' :
					nLast -= parseFloat(Readout);
					break;
				case '×' :
					nLast *= parseFloat(Readout);
					break;
				case '÷' :
					nLast /= parseFloat(Readout);
					break;
				default :
					nLast = parseFloat(Readout);
					break;
			}
			switch(opr)
			{
				case '+' :
				case '－' :
					prompt.innerHTML += opr;
					break;
				case '×' :
				case '÷' :		
					if(sLastOpr == '×' || sLastOpr == '÷' || sLastOpr == ""){
						prompt.innerHTML += opr;
					}else{
						prompt.innerHTML = "("+prompt.innerHTML+")"+opr;
					}
					break;
				case '=' :
					break;
				default :
					break;
			}
			result.value = nLast;
			sLastOpr = opr;
		}
	}
 
	function inputDecimal()
	{
		var value = result.value;
		if (bNewNum) {
			value = "0.";
			prompt.innerHTML += "0.";
			bNewNum = false;
		}else{
			if (value.indexOf(".") == -1){
				value += ".";
				if(prompt.innerHTML == ""){
					prompt.innerHTML = "0.";
				}else{
					prompt.innerHTML += "."; 
				}
			}
		}
		result.value = value;
	}
 
	function clearAll()
	{
		nLast = 0;
		sLastOpr = "";
		result.value = "0";
		prompt.innerHTML = "";
		bNewNum = true;
	}
 
	function negative() 
	{
		result.value = parseFloat(result.value) * -1;
		prompt.innerHTML = "-("+prompt.innerHTML+")";
	}	
//-->
</script>
<style> 
body {margin:0 auto;text-align:center;}
.Cont{margin:0}
.sxjsq_tab{width:390px;table-layout:fixed;}
.sx_J_11{width:4px;height:80px;font-size:0px;}
.sx_J_12{width:380px;height:80px;vertical-align:top;text-align:center;}
.sx_J_13{width:6px;height:80px;font-size:0px;}
.sx_J_21{width:390px;}
.sx_J_31{width:390px;height:7px;font-size:0px;}
 
.sec_box_JSQ_table{width:360px;margin:15px auto}
.sec_box_JSQ_table td{text-align:center;width:20%;}
.sec_box_JSQ_table input{width:66px;height:33px;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:16px;font-weight:bold;color:#1919CD;line-height:24px;}
 
.sec_box_NOS{margin:17px auto;text-align:center}
.sec_box_int1{width:5px;height:39px;background:url(img/jsq_int.gif) no-repeat 0 0;}
.sec_box_int2{height:39px;background:url(img/jsq_int.gif) repeat-x 0 -39px;}
.sec_box_int3{width:3px;height:39px;background:url(img/jsq_int.gif) no-repeat -5px 0;}
.sec_box_NOS input{width:340px;font-family:"Arial";font-weight:bold;font-size:24px;color:#000;padding:2px 5px;letter-spacing:2px;background-color:transparent;border:0;}
input.jsq_btn_B{height:72px;line-height:60px;COLOR: #B50506;}
input.fsize18{font-size:18px;}
 
.tips_p{float:left;position:relative;width:100%;}
.sec_box_NON{position:absolute;top:3px;left:50%;margin-left:-178px;width:355px;height:20px;line-height:20px;text-align:left;text-indent:8px;white-space:nowrap;text-overflow:ellipsis;font-size:12px;color:#333;overflow:hidden;}
 
</style>
</head>
<body lang="zh" onload="fInit();">
<div class="Cont">
<table align="center" cellpadding="0" cellspacing="0" class="sxjsq_tab">
  <tr style="height:30px">
    <td class="sx_J_11"></td>
    <td class="sx_J_12">
		<div class="sec_box_NOS">
    <table border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td class="sec_box_int1"></td>
              <td class="sec_box_int2"><input name="text" type="text" id="jsqResult" style="text-align:right" value="0" size="13" maxlength="13" readonly="true" /></td>
              <td class="sec_box_int3"></td>
            </tr>
          </table>
    <!--下面隐藏的层，当输入算式时出现-->
    <div class="tips_p" >
      <div class="sec_box_NON">算式提示：<span id="jsqPrompt"></span></div>
    </div>
  </div>
	
	</td>
    <td class="sx_J_13"></td>
  </tr>
  <tr>
    <td colspan="3" class="sx_J_21">
	<table border="0" cellpadding="3" cellspacing="0" class="sec_box_JSQ_table">
      <tr>
        <td><input type="button"  value="7"  onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="8"  onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="9"  onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="÷" onclick="operate(this.value)"style="COLOR: #B50506;"></td>
        <td rowspan="2"><input type="button"   value="清零" onclick="clearAll()" class="jsq_btn_B"></td>
      </tr>
      <tr>
        <td><input type="button"  value="4"  onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="5"  onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="6"  onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="×" onclick="operate(this.value)" style="COLOR: #B50506;"></td>
      </tr>
      <tr>
        <td><input type="button"  value="1"  onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="2"  onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="3"  onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="－" onclick="operate(this.value)" style="COLOR: #B50506;"></td>
        <td rowspan="2"><input type="button"   value="="  onclick="operate(this.value)" class="jsq_btn_B fsize18"></td>
      </tr>
      <tr>
        <td><input type="button"  value="0" onclick="inputNum(this.value)"></td>
        <td><input type="button"  value="±" onclick="negative()"></td>
        <td><input type="button"  value="." onclick="inputDecimal()"></td>
        <td><input type="button"  value="+" onclick="operate(this.value)" style="COLOR: #B50506;"></td>
      </tr>
    </table
	></td>
    </tr>
    <!-- <tr>
    <td colspan="3" class="sx_J_31"></td>
    </tr> -->
</table>
</div>
</body>
</html>